<!--
  @author: 善良的YWJ
  @Created by shanliangdeYWJ on 2020/09/16 02:50:01
  @file: Transport.vue
  @description:
  ==================
  Service 下的 Transport
  ==================
  @link [Github](https://github.com/shanliangdeYWJ)
-->

<template>
  <div class="transport">
    <NavigationFrame class="card-btn" :totalWidth="35+'%'" :lists="lists" :active="myindex" />
    <div class="card-content clearfix">
      <div class="box1" v-show="myindex===0">
        <div class="map-box">
          <Map @showNewLocal="showNewLocal" :map="map" />
        </div>
        <div class="btn-group">
          <div class="btn-group-height">
            <swiper ref="btnSwiper" :options="options" style="height:479px;">
              <swiper-slide
                class="swiper-no-swiping local-btn-box"
                v-for="(item,index) in localList"
                :key="index"
                @click.native="()=>showNewLocal(item.center,item.infoWindow)">
                <div class="local-btn">
                  <h5 class="title">{{item.infoWindow.title}}</h5>
                  <p class="address">{{item.infoWindow.address}}</p>
                </div>
              </swiper-slide>
              <!-- 地图位置展示按钮swiper移动按钮 -->
              <!-- <div class="swiper-btn swiper-button-prev" slot="button-prev"></div> -->
              <!-- <div class="swiper-btn swiper-button-next" slot="button-next"></div> -->
            </swiper>
            <div class="swiper-btn-box">
              <div class="swiper-btn my-swiper-btn-prev"
                @click="swiperbtn(activeIndex,-1)">上一个</div>
              <div class="swiper-btn my-swiper-btn-next"
                @click="swiperbtn(activeIndex,+1)">下一个</div>
            </div>
          </div>

        </div>
      </div>
      <!-- <div class="box2" v-show="myindex===1">2</div> -->
    </div>
  </div>
</template>

<script>
import NavigationFrame from '@/components/navigation-frame.vue';
import Map from '@/components/map/map.vue';
import 'swiper/dist/css/swiper.css';
import { swiper, swiperSlide } from 'vue-awesome-swiper/src/index';
export default {
  name: 'GFTransport',
  components: { NavigationFrame, Map, swiper, swiperSlide },
  data () {
    return {
      activeIndex: 0,
      options: {
        direction: 'vertical',
        navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev' },
        autoplay: false,
        slidesPerView: 4,
        noSwiping: true
      },
      myindex: 0,
      map: {
        infoWindow: { open: false, content: { title: '上海-上海市', address: '具体地址XXXXXXXXX' } },
        center: { lng: 121.4472540000, lat: 31.3236200000 },
        zoom: 15,
        dragging: false
      },
      lists: [{ name: '配送服务', click: this.navFClick }, { path: '#', name: '旗舰店' }],
      localList: [
        { infoWindow: { title: '上海-上海市', address: '具体地址具体地址具体地址具体地址具体地址具体地址具体地址具体地址具体地址具体地址具体地址' }, center: { lng: 121.4472540000, lat: 31.3236200000 } },
        { infoWindow: { title: '云南省-临沧市', address: '具体地址XXXXXXXXX' }, center: { lng: 100.092612914, lat: 23.8878061038 } },
        { infoWindow: { title: '云南省-丽江市', address: '具体地址XXXXXXXXX' }, center: { lng: 100.229628399, lat: 26.8753510895 } },
        { infoWindow: { title: '云南省-保山市', address: '具体地址XXXXXXXXX' }, center: { lng: 99.1779956133, lat: 25.1204891962 } },
        { infoWindow: { title: '云南省-大理白族自治州', address: '具体地址XXXXXXXXX' }, center: { lng: 100.223674789, lat: 25.5968996394 } },
        { infoWindow: { title: '广东省-深圳市', address: '具体地址XXXXXXXXX' }, center: { lng: 114.025973657, lat: 22.5460535462 } }
      ]
    };
  },
  methods: {
    showNewLocal (center, content) {
      this.map.infoWindow.content = content;
      this.map.center = center;
    },
    swiperbtn (activeIndex, num) {
      const len = this.btnSwiper.slides.length;
      const next = activeIndex + num;
      const slidesPerView = this.options.slidesPerView;
      if (next < 0 || next > (len - slidesPerView)) return;
      this.activeIndex = next;
      this.btnSwiper.slideTo(next, 1000);
    },
    change: (e) => { console.log(e); },
    navFClick (item, index) { this.myindex = index; }
  },
  computed: { btnSwiper () { return this.$refs.btnSwiper.swiper; } }
};
</script>

<style lang='scss' scoped>
.transport {
  background-color: var(--bg);

  ::v-deep.navigation-frame {
    padding: 20px 0;
    width: 90%;
    margin: 0 auto;

    // 导航
    a {
      padding: 20px;
      color: #747474;
      background: #ffffff;
      margin: 0 20px;
      border-radius: 10px;
      border: 1px solid #dddddd;
      font-size: 16px;

      &::before {
        display: none;
      }

      &:hover {
        background: #e1e1e1;
      }
    }

    .router-link-active {
      background: #ffffff;
    }

    .itemActive {
      background: #e1e1e1;
    }
  }
}

// 卡片内容视图
.card-content {
  width: 80%;
  margin: 0 auto;

  // 地图盒子
  .map-box {
    width: 75%;
    padding: 10px;
    float: left;
    box-sizing: border-box;
    background-color: #ffffff;
  }

  // 按钮盒子百分比 padding-bottom
  .btn-group-height {
    position: relative;
    overflow: hidden;
    background-color: #f9f9f9;
    width: 100%;
    padding: 10px 0;
    box-sizing: border-box;
    height: 0;
    padding-bottom: (1330 / 826) * 100%;
  }

  .btn-group {
    float: left;
    width: 25%;
  }

  // 按钮组实际控制位置的按钮
  .local-btn-box {
    border-bottom: 1px solid #969696;
    padding: 20px;
    box-sizing: border-box;
    cursor: pointer;
  }
  .local-btn {
    h5 {
      font-size: 20px;
    }
    p {
      font-size: 12px;
      text-indent: 2em;
    }
  }

  // #region  swiper按钮的位置
  .swiper-btn-box {
    position: absolute;
    bottom: 0;
    z-index: 10;
    color: #ffffff;
    text-align: center;
    font-size: 20px;
    font-weight: 400;
    width: 100%;
  }
  // #endregion
  // #region  按钮的外观样式
  .swiper-btn {
    display: inline-block;
    width: 50%;
    cursor: pointer;
    user-select: none;
    padding: 5px;
    box-sizing: border-box;
  }
  .my-swiper-btn-prev {
    background: #c30d23;
  }
  .my-swiper-btn-next {
    background: #555;
  }

  // #endregion
}
</style>
